<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:jsf="http://xmlns.jcp.org/jsf"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:p="http://primefaces.org/ui">

    <div>
        <p:panel header="Inscribir Un Nuevo Socio" style="border:none;">
            <p>
                Para nuestros nuevos socios, primero debe verificar si ya existe
                en la base de datos, por lo que debe ingresar primero su DNI para
                tener un control completo del nuevo socio.
            </p>

            <p:separator/>
            <h:outputText value="DATOS PERSONALES" style="color: #0066ff;text-shadow: 0px 2px 3px #555; font-size: 20px"/>
            <p:separator />
            <h:form id="formDniPerson">
                <div class="dynaFormLabel">  
                    <p:outputLabel for="dni" value="Dni"/>  
                </div>
                <p:inputText id="dni" label="Dni" maxlength="8"
                             value="#{businessAssociateBean.person.dni}" >
                    <f:validateLength minimum="8"/>
                    <p:ajax event="blur" 
                            listener="#{businessAssociateBean.searchPersonForRegisterAssociate()}"
                            update=":formRegisterComplete:txt,:formRegisterComplete:txt1,:formRegisterComplete:txt2,:formRegisterComplete:txt4,:formRegisterComplete:txt5,:formRegisterComplete:txt6,:formRegisterComplete:nac,:formRegisterComplete:addre,:formRegisterComplete:working,:formRegisterComplete:univer,:formRegisterComplete:depart,:formRegisterComplete:province,:formRegisterComplete:distict,:formRegisterComplete:photoCheck,:formRegisterComplete:codeCard,:formRegisterComplete:apertureId,:formRegisterComplete:startDateId,:formRegisterComplete:codeCourse"/>
                </p:inputText>
                <!--
                <p:commandButton update=":formRegisterComplete"
                                 icon="ui-icon-search" action="#{businessAssociateBean.searchPersonForRegisterAssociate()}"/>
                -->
            </h:form>
            <h:form id="formRegisterComplete"> 
                <h:panelGrid columns="3" cellspacing="10">
                    <h:panelGrid >
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="txt" value="Nombres"/>  
                        </div>  
                        <h:inputText id="txt" required="true" label="Nombres" maxlength="25"
                                     value="#{businessAssociateBean.person.name}"/>
                    </h:panelGrid>
                    <h:panelGrid>
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="txt1" value="Ap. Paterno"/>  
                        </div>  
                       <h:inputText id="txt1" required="true" label="Ap. Paterno" maxlength="25"
                                     value="#{businessAssociateBean.person.fatherName}"/>
                    </h:panelGrid>
                    <h:panelGrid>
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="txt2" value="Ap. Materno"/>  
                        </div>  
                        
                        <h:inputText id="txt2" required="true" label="Ap. Materno" maxlength="25"
                                     value="#{businessAssociateBean.person.motherName}"/>
                    </h:panelGrid>
                    <h:panelGrid>
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="txt4" value="Telefono"/>  
                        </div>  
                        <h:inputText id="txt4" label="Telefono" maxlength="19"
                                     value="#{businessAssociateBean.person.phone2}"/>
                    </h:panelGrid>
                    <h:panelGrid>
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="txt5" value="Celular"/>  
                        </div>  
                        <h:inputText id="txt5" label="Celular" maxlength="19"
                                     value="#{businessAssociateBean.person.phone}"/>
                    </h:panelGrid>
                    <h:panelGrid >
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="txt6" value="Email"/>  
                        </div>  
                        <p:inputText id="txt6" required="true" label="Email"
                                     validatorMessage="Correo Inválido" maxlength="79"
                                     value="#{businessAssociateBean.person.email}" >
                            <f:validateRegex
                                pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
                        </p:inputText>
                    </h:panelGrid>
                    <h:panelGrid >
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="nac" value="Fecha de Nacimiento"/>  
                        </div>  
                        <p:calendar id="nac" label="Fecha de Nacimiento" locale="es"
                                    value="#{businessAssociateBean.person.birthday}" />
                    </h:panelGrid>
                    <h:panelGrid >
                        <div class="dynaFormLabel"> 
                            <p:outputLabel for="addre" value="Dirección"/>  
                        </div>  
                        <h:inputText id="addre"  label="Dirección" maxlength="99"
                                     value="#{businessAssociateBean.person.addressHome}" />
                    </h:panelGrid>
                    <h:panelGrid >
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="working" value="Centro de Trabajo"/>  
                        </div>  
                        <h:inputText id="working"  label="Centro de Trabajo" maxlength="99"
                                     value="#{businessAssociateBean.person.workingData}" />
                    </h:panelGrid>
                </h:panelGrid>
                <!-- DESDE AQUI VIENEN LOS COMBOS -->
                <div class="dynaFormLabel">  
                    <p:outputLabel for="univer" value="Universidad o  Intituto"/>  
                </div>  
                <h:panelGrid columns="2">
                    <p:selectOneMenu id="univer" converter="universityconvert"
                                     filter="true" filterMatchMode="contains"
                                     value="#{businessAssociateBean.person.idUniversity}">
                        <f:selectItem itemLabel="Seleccione una universidad" noSelectionOption="true"/>

                        <f:selectItems value="#{businessAssociateBean.listUniversity}" var="university"
                                       itemLabel="#{university.name}" itemValue="#{university}" />
                    </p:selectOneMenu>
                    <p:commandButton process="@none" icon="fa fa-plus-circle" 
                                     action="#{businessAssociateBean.clearUniversity()}"
                                     update=":formaddUniversity:addUniv"
                                     oncomplete="addNewUniversity.show();"/>
                </h:panelGrid>
                <h:panelGrid columns="2">
                    <h:panelGrid >
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="depart" value="Departamento"/>  
                        </div>  
                        <p:selectOneMenu id="depart" value="#{businessAssociateBean.idDepartment}">
                            <f:selectItem itemLabel="Seleccione una Departamento"  />
                            <f:selectItems value="#{businessAssociateBean.listDepartment}" var="department"
                                           itemLabel="#{department.name}" itemValue="#{department.id}" />
                            <p:ajax event="change" update="province"
                                    listener="#{businessAssociateBean.updateProvince()}"/>
                        </p:selectOneMenu>
                    </h:panelGrid>
                    <h:panelGrid>
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="province" value="Provincia"/>  
                        </div>  
                        <p:selectOneMenu id="province" value="#{businessAssociateBean.idProvince}">
                            <f:selectItem itemLabel="Seleccione una Provincia" noSelectionOption="true"/>
                            <f:selectItems value="#{businessAssociateBean.listProvince}" var="provinc"
                                           itemLabel="#{provinc.name}" itemValue="#{provinc.id}" />
                            <p:ajax event="change" update="distict"
                                    listener="#{businessAssociateBean.updateDistrict()}"/>
                        </p:selectOneMenu>
                    </h:panelGrid>
                    <h:panelGrid>
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="distict" value="Distrito"/>  
                        </div>  
                        <p:selectOneMenu id="distict" 
                                         value="#{businessAssociateBean.idDistrict}">
                            <f:selectItem itemLabel="Seleccione un Distrito"/>
                            <f:selectItems value="#{businessAssociateBean.listDistrict}" var="disc"
                                           itemLabel="#{disc.name}" itemValue="#{disc.id}" />
                        </p:selectOneMenu>
                    </h:panelGrid>
                    <h:panelGrid>
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="photoCheck" value="Entrego Foto?"/>  
                        </div>  
                        <h:selectBooleanCheckbox id="photoCheck" value="#{businessAssociateBean.person.photoCheck}" />
                    </h:panelGrid>
                </h:panelGrid>
                <!-- FINALIZACION DE LOS COMBOS -->
                <p class="separator"/>
                <p:separator />
                <h:outputText value="DATOS DE SOCIO" style="color: #0066ff;text-shadow: 0px 2px 3px #555; font-size: 20px"/>
                <p:separator />
                <h:panelGrid columns="3">
                    <h:panelGrid >
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="codeCard" value="Código Carnet"/>  
                        </div>
                        <p:inputMask value="#{businessAssociateBean.businessAssociate.codeCard}" 
                                     id="codeCard" mask="9999"
                                     placeholder="0001" label="Código Carnet">
                        </p:inputMask>
                    </h:panelGrid>
                    <!--
                    <h:panelGrid >
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="spiner" value="Descuento (%)"/>  
                        </div>
                        <p:spinner min="0" max="100" id="spiner" placeholder="Porcentaje de DSC %"
                                   value=""/>
                    </h:panelGrid>
                    -->
                    <h:panelGrid >
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="apertureId" value="De que año es el Socio?"/>  
                        </div>
                        <p:selectOneMenu id="apertureId" value="#{businessAssociateBean.businessAssociate.idApertureAssociate}"
                                         converter="apertureassociateconvert" required="true">

                            <f:selectItems value="#{businessAssociateBean.listApertureAssociate}" var="apert"
                                           itemLabel="#{apert.year}" itemValue="#{apert}" />
                        </p:selectOneMenu>
                    </h:panelGrid>
                    <h:panelGrid>
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="startDateId" value="Fecha Registro"/>  
                        </div>
                        <p:calendar locale="es" id="startDateId" required="true" label="Fecha Registro"
                                    value="#{businessAssociateBean.businessAssociate.startDate}" 
                                    pattern="dd-MM-yyyy" placeholder="Día-Mes-Año"/>
                    </h:panelGrid>
                    <h:panelGrid>
                        <div class="dynaFormLabel">  
                            <p:outputLabel for="codeCourse" value="Código Curso"/>  
                        </div>
                        <p:inputText id="codeCourse" label="Código Curso" maxlength="40"
                                     value="#{businessAssociateBean.businessAssociate.codeCourse}" 
                                     placeholder="JDJ FDS 003 12/01/2014" size="30"/>
                    </h:panelGrid>
                </h:panelGrid>
                <p:separator />
                <div align="center">
                    <p:commandButton value="Guardar" style="color:#0066ff;" 
                                     icon="ui-icon-disk" update=":formRegisterComplete:txt txt1 txt2 txt4 txt5 txt6 nac addre working univer depart province distict codeCard codeCourse apertureId,:formDniPerson:dni"
                                     action="#{businessAssociateBean.saveOrUpdatePersonAndAssociate()}"/>
                </div>
                <p:separator />
            </h:form>

        </p:panel>
    </div>

    <p:dialog header="Nueva Universidad o Instituto" appendTo="@(body)"
              modal="true" id="addNewUniversityId" widgetVar="addNewUniversity">

        <h:form id="formaddUniversity">
            <div class="dynaFormLabel">  
                <p:outputLabel for="addUniv" value="Universidad"/>  
            </div> 
            <p:inputText id="addUniv" value="#{businessAssociateBean.univesityAdd.name}"
                         required="true" label="Universidad" size="45"/>
            <p:commandButton value="Guardar" icon="ui-icon-disk" 
                             action="#{businessAssociateBean.saveOrUpdateUniversity()}"
                             oncomplete="if(!args.validationFailed){addNewUniversity.hide();}"
                             update=":formRegisterComplete:univer"/>             
        </h:form>
    </p:dialog>

</ui:composition>